package com.cx.dao;

import com.cx.pojo.Club;
import com.cx.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;


public interface ClubMapper {

    //    =====================================================================
//    根据用户id查询加入的社团信息
    public List<Club> getAllClubById(Integer id);

    //根据社团id退出
    @Delete("delete from club_type_userid where Club_ID = #{clubID} and id = #{id}")
    public void getDeleteClubById(@Param("clubID") Integer clubID, @Param("id") Integer id);

    //    团队成员的基本信息情况的在线查询
    @Select("SELECT u.* FROM `club_type_userid` t LEFT JOIN `t_user` u ON u.`id`=t.`id`  WHERE t.`club_ID`= #{id}")
    public List<User> getClubByIdList(Integer id);

//    =====================================================================

    //    添加社团
    @Insert("INSERT INTO club(`Club_name`,`level`,`Club_style`,`club_recruitment`,`contact_us`,`founder`) " +
            "VALUES (#{clubName}, #{level}, #{clubStyle}, #{clubRecruitment}, #{contactUs}, #{founder});")
    public void addClub(Club club);


    //    加入社团
    @Insert("INSERT INTO club_type_userid(`Club_ID`,`id`) VALUES (#{clubID}, #{id});")
    public void clubAddUser(@Param("clubID") Integer clubID, @Param("id") Integer id);

    //    查看是否已经加入该社团
    @Select("SELECT `club_user_id` FROM `club_type_userid`  WHERE `Club_ID`=#{clubID} AND `id`=#{id}")
    public Integer clubAddUserById(@Param("clubID") Integer clubID, @Param("id") Integer id);

    //    根据id删除指定的社团信息
    @Delete("delete from club where Club_ID = #{id}")
    public void deleteClubById(Integer id);
   //    根据id删除指定的社团信息
    @Delete("DELETE FROM `club_type_userid` WHERE Club_ID = #{id}")
    public void deleteClubTypeUseridById(Integer id);


    //    根据id修改社团信息
    @Update("update club set club_name=#{clubName}, level = #{level}, club_style = #{clubStyle}, " +
            "Club_recruitment = #{clubRecruitment}, contact_us = #{contactUs} where Club_ID=#{clubID};")
    public void updateClub(Club club);

    //    查询所有社团信息
    public List<Club> getAllClub(@Param("st") Integer currentPage, @Param("pageSize") Integer pageSize);

    //    根据id查询指定的社团信息
    public Club getClubById(Integer id);

    //    查询总记录数
    @Select("select count(*) from club")
    public int count();

    //    根据社团名查询指定的社团信息
    @Select("select  * from club where club_name = #{clubName}")
    public Club checkName(String name);


}
